﻿#include "mypainer.h"

Mypainer::Mypainer()
{

}

void Mypainer::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    //QStyledItemDelegate::paint(painter,option,index);
    QImage image;
    QVariant ret=index.model()->data(index);//index.model获取表格数据模型，在通过该模型获取索引为index的数据
    qDebug()<<ret;
    if(ret=="未添加")
    {
        image.load(":/image/2.png");
    }else if(ret=="已添加")
    {
        image.load(":/image/1.png");
    }
    QRect rect=option.rect;
    qDebug()<<option.rect;
    rect.setWidth(75);
    rect.setLeft(460);
    painter->drawImage(rect,image);

}
